package suanfa;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/9/2-下午8:19
 * Since  :   1.0
 * Version:   1.0
 */
public class Solution5 {
    public static void main(String[] args) {

        int[] a=new int[1000];
        int[] b=new int[1000];
        a[0]=1;
        b[0]=2;
        for (int i = 1; i < 1000; i++) {
            a[i]=i;
            b[i]=i;
        }


        long start = System.currentTimeMillis();
        System.out.println(findMinTime(1000,a,b));
        long end = System.currentTimeMillis();
        System.out.println(end-start);

    }

    public static int findMinTime(int n,int arrA[],int arrB[]){
        int aIndex=0;
        int aValue=arrA[0];

        int aSecondValue=Integer.MAX_VALUE;

        int bIndex=0;
        int bValue=arrB[0];

        int bSecondValue=Integer.MAX_VALUE;
        for(int i=0;i<n;i++){
            if (arrA[i]<aValue){
                aValue=arrA[i];
                aIndex=i;
            }
        }
        for(int i=0;i<n;i++){
            if (i==aIndex)
                continue;
            if (arrA[i]<aSecondValue){
                aSecondValue=arrA[i];

            }
        }

        for(int i=0;i<n;i++){
            if (arrB[i]<bValue){
                bValue=arrB[i];
                bIndex=i;
            }
        }
        for(int i=0;i<n;i++){
            if (i==bIndex)
                continue;
            if (arrB[i]<bSecondValue){
                bSecondValue=arrB[i];
            }
        }


        if (aIndex!=bIndex){
            return bValue>aValue?bValue:aValue;
        }else {
            int max=0;
            int secondTime=0;
            int sum=aValue+bValue;
            if (aValue>bValue){
                max=aValue;
                secondTime=bSecondValue;
                if (secondTime>sum){
                    return sum;
                }else if (secondTime<aValue) {
                    return  aValue;
                }
                else {
                    return  secondTime;
                }
            }else {
                max=bValue;
                secondTime=aSecondValue;
                if (secondTime>sum){
                    return sum;
                }else if (secondTime<aValue) {
                    return  bValue;
                }
                else {
                    return  secondTime;
                }

            }



        }



    }
}
